package P3;

import NIOCommunication.NIOProcessor;
import NIOCommunication.NIOSocketContext;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;

public class CoordinatorInterface extends CoordinationContext
{
    private Worker mWorker;
    private boolean mClosed = false;
    private boolean mTimedOut = false;
    
    public CoordinatorInterface(Worker worker, NIOProcessor processor, InetSocketAddress address)
    {
        super(processor, address);
        mWorker = worker;
    }
    
    @Override
    public void OnNewMessage(String message)
    {
        mWorker.OnNewMessage(message);
    }
    
    @Override
    public void OnChannelClosed(NIOSocketContext context)
    {
        mClosed = true;
        if(mWorker != null)
        {
            mWorker.OnCoordinatorDisconnected(this);
        }
    }
    
    @Override
    public void OnTimeout()
    {
        mTimedOut = true;
        mWorker.OnCoordinatorTimedout(this);
    }
    
    public boolean IsClosed()
    {
        return mClosed;
    }
    
    public boolean IsTimedOut()
    {
        return mTimedOut;
    }
}
